﻿// Copyright (c) Yoganand R. All rights reserved.
// For continued development and updates, visit http://yogsbreath.com
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.UI;

namespace MVCnExt.Web.UI.Ext
{
    /// <summary>
    /// Abstraction for ClientScriptManager so we can author Ajax controls for both
    /// MVC applications as well as standard WebForms applications
    /// </summary>
    public abstract class ClientScriptManagerBase
    {
        private ListDictionary _cssScriptBlocks = new ListDictionary();

        #region Custom Implementation Methods

        /*
         * This section consists of methods which will allow us to register 
         * stylesheet references in the page's head section for our custom 
         * Ajax controls
         */

        public virtual bool IsClientCssIncludeRegistered(Type type, string key)
        {
            ScriptKey scriptKey = new ScriptKey(type, key, true);

            return IsClientCssIncludeRegistered(scriptKey);
        }

        public virtual bool IsClientCssIncludeRegistered(string key)
        {
            return IsClientCssIncludeRegistered(typeof(Page), key);
        }

        internal bool IsClientCssIncludeRegistered(ScriptKey key)
        {
            return _cssScriptBlocks.Contains(key);
        }

        internal void RegisterClientCssInclude(ScriptKey key, String url)
        {
            if (IsClientCssIncludeRegistered(key))
                return;

            _cssScriptBlocks.Add(key, url);

            RenderClientCssInclude(url);
        }

        public virtual void RegisterClientCssInclude(Type type, string key, string url)
        {
            ScriptKey scriptKey = new ScriptKey(type, key, true);

            RegisterClientCssInclude(scriptKey, url);
        }

        public virtual void RegisterClientCssInclude(string key, string url)
        {
            RegisterClientCssInclude(typeof(Page), key, url);
        }

        protected virtual ListDictionary GetClientCssIncludes()
        {
            return _cssScriptBlocks;
        }

        protected abstract void RenderClientCssInclude(String url);

        #endregion

        #region ClientScriptManager methods

        /*
         * This section is to be used to define the methods we can use for the ClientScriptManager
         */

        public abstract string GetCallbackEventReference(Control control, string argument, string clientCallback, string context);

        public abstract string GetCallbackEventReference(Control control, string argument, string clientCallback, string context, bool useAsync);

        public abstract string GetCallbackEventReference(string target, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync);

        public abstract string GetCallbackEventReference(Control control, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync);

        public abstract string GetPostBackClientHyperlink(Control control, string argument);

        public abstract string GetPostBackClientHyperlink(Control control, string argument, bool registerForEventValidation);

        public abstract string GetPostBackEventReference(PostBackOptions options);

        public abstract string GetPostBackEventReference(Control control, string argument);

        public abstract string GetPostBackEventReference(PostBackOptions options, bool registerForEventValidation);

        public abstract string GetPostBackEventReference(Control control, string argument, bool registerForEventValidation);

        public abstract string GetWebResourceUrl(Type type, string resourceName);

        public abstract bool IsClientScriptBlockRegistered(string key);

        public abstract bool IsClientScriptBlockRegistered(Type type, string key);

        public abstract bool IsClientScriptIncludeRegistered(string key);

        public abstract bool IsClientScriptIncludeRegistered(Type type, string key);

        public abstract bool IsOnSubmitStatementRegistered(string key);

        public abstract bool IsOnSubmitStatementRegistered(Type type, string key);

        public abstract bool IsStartupScriptRegistered(string key);

        public abstract bool IsStartupScriptRegistered(Type type, string key);

        public abstract void RegisterArrayDeclaration(string arrayName, string arrayValue);

        public abstract void RegisterClientScriptBlock(Type type, string key, string script);

        public abstract void RegisterClientScriptBlock(Type type, string key, string script, bool addScriptTags);

        public abstract void RegisterClientScriptInclude(string key, string url);

        public abstract void RegisterClientScriptInclude(Type type, string key, string url);

        public abstract void RegisterClientScriptResource(Type type, string resourceName);

        public abstract void RegisterExpandoAttribute(string controlId, string attributeName, string attributeValue);

        public abstract void RegisterExpandoAttribute(string controlId, string attributeName, string attributeValue, bool encode);

        public abstract void RegisterForEventValidation(string uniqueId);

        public abstract void RegisterForEventValidation(PostBackOptions options);

        public abstract void RegisterForEventValidation(string uniqueId, string argument);

        public abstract void RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue);

        public abstract void RegisterOnSubmitStatement(Type type, string key, string script);

        public abstract void RegisterStartupScript(Type type, string key, string script);

        public abstract void RegisterStartupScript(Type type, string key, string script, bool addScriptTags);

        public abstract void ValidateEvent(string uniqueId);

        public abstract void ValidateEvent(string uniqueId, string argument);

        #endregion
    }
}
